#include <iostream>
#include <ostream>
#include <algorithm>
//#include <algorithmfwd.h>
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <typeinfo>
#include <vector>
#include<bits/stl_algo.h>
#include<bits/algorithmfwd.h>

using namespace std;
//using namespace boost:assign;
template <typename I>
typename iterator_traits<I>::value_type
get_n(I& iter, int n)
{
    return *(next(iter, n));
}


template <typename I>
auto
get_n2(I& iter, int n)
->decltype(*(next(iter, n)))
{
    return *(next(iter, n));
}

template <typename I>
auto
get_n3(I& iter, int n)
->decltype(*(next(iter, n)))
{
    return *(next(iter, n));
}

void iterator_main()
{
    vector<int> v1, v2;

    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);

    v2.push_back(11);
    v2.push_back(12);
    v2.push_back(13);
    v2.push_back(14);
    v2.push_back(15);

    logInfo("v2.size=%d", v2.size());
  //  cout << v2;
    logInfo("%d %d %d %d %d", v2[0], v2[1], v2[2], v2[3], v2[4]);
   // std::copy(v1.begin(), v1.end(),
    //        reverse_iterator<int>(v2.begin()) );
    logInfo("%d %d %d %d %d", v2[0], v2[1], v2[2], v2[3], v2[4]);
    logInfo("v2.size=%d", v2.size());
  //  cout << v2;
    //auto distance1 = ;
    logInfo("distance1=%d,distance2=%d",
           distance(v1.end() + 2, v1.begin()), distance(v1.begin(), v2.end()));
    auto it = v1.begin() + 1;
    advance(it, -1);
    logInfo("it=%d", *it);
    //cout<<v2;
//   std::copy(v2.begin(), v2.end(),
 //             ostream<int>(cout));

    auto p1 = v1.begin();
    auto p2 = v1.end();
    logInfo("p1 + 1= %d", get_n2(p1, 1));
    logInfo("p1 - 1 = %d", get_n2(p1, -1));
    logInfo("p2 - 1 = %d", get_n2(p2, -1));

    logInfo("v1=%d %d %d %d %d", v1[0], v1[1], v1[2], v1[3], v1[4]);
    logInfo("v2=%d %d %d %d %d", v2[0], v2[1], v2[2], v2[3], v2[4]);

//    remove_copy(v1.begin(), v1.end(), v2.begin(), 3);

    auto lamb1 = [](vector<int>::iterator x)->bool
    {

        return true;
        /*
            if (*x == 3)
            {
                return true;
            }
            else
            {
                return false
            }*/
};

  //  remove_copy_if(v1.begin(), v1.end(), v2.begin(), lamb1);

    auto fun2 = bind2nd(modulus<int>(), 2);
    auto fun3=
   // remove_copy_if(v1.begin(), v1.end(), v2.begin(),
   //                bind2nd(modulus<int>(), 2));

   // remove_copy_if(v1.begin(), v1.end(), v2.begin(),fun3
     //                 );

    remove_copy_if(v1.begin(), v1.end(), v2.begin(),
                   [](int& x){return x % 3 == 0;}
    );
    replace_copy_if(v1.begin(), v1.end(), v2.begin(),
                    [](int& x){return x % 3 == 0;}
    ,34
     );

    logInfo("v1=%d %d %d %d %d", v1[0], v1[1], v1[2], v1[3], v1[4]);
    logInfo("v2=%d %d %d %d %d", v2[0], v2[1], v2[2], v2[3], v2[4]);

//

}


